﻿using System.Collections.Generic;
using System.Diagnostics.Contracts;
using Socium.Domain.Collections;
using Socium.Domain.Persons;
using Socium.Domain.Tests.Testings;
using Socium.Presentation;

namespace Socium.Testings {
	abstract class TreeItemBase : ViewModelBase {
		protected TreeItemBase(string display_name) {
			DisplayName = display_name;
		}

		public string DisplayName { get; private set; }

		public abstract void Load(Person person, Testing testing);
		public abstract void Save(Person person, Testing testing);
	}

	abstract class TreeItemBase<TModel> : TreeItemBase {
		readonly TModel _model;

		protected TreeItemBase(TModel model, string display_name) : base(display_name) {
			_model = model;
		}

		public TModel Model {
			get { return _model; }
		}
	}

	abstract class TreeItemBase<TModel, TChild> : TreeItemBase<TModel> {
		protected TreeItemBase(TModel model, string display_name) : base(model, display_name) {
			_childeren.AddRange(GetChilderen(model));
		}

		readonly ICollection<TChild> _childeren = new LinkedList<TChild>();

		public IEnumerable<TChild> Childeren {
			get { return _childeren; }
		}

		[Pure]
		protected abstract IEnumerable<TChild> GetChilderen(TModel model);
	}
}
